/*
 * Galaxium Messenger
 * 
 * Copyright (C) 2008 Paul Burton <paulburton89@gmail.com>
 * 
 * License: GNU General Public License (GPL)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

using Anculus.Core;

namespace Galaxium.Protocol.Msn.Soap.BodyParts
{
	public enum MemberType { Unknown, Passport, Email, Phone, Role, Group, Everyone }
	public enum MemberState { Unknown, Accepted }
	
	[XmlRoot (Namespace=SoapConstants.nsAddressBook)]
	[XmlInclude (typeof (PassportMember))]
	[XmlInclude (typeof (RoleMember))]
	[XmlInclude (typeof (EveryoneMember))]
	[XmlInclude (typeof (EmailMember))]
	[XmlInclude (typeof (PhoneMember))]
	[XmlInclude (typeof (GroupMember))]
	[XmlInclude (typeof (ServiceMember))]
	[XmlInclude (typeof (DomainMember))]
	public class Member
	{
		long _membershipId;
		bool _membershipIdSpecified = false;
		string _type;
		string _state;
		bool _deleted;
		bool _deletedSpecified = false;
		DateTime _lastChanged;
		bool _lastChangedSpecified = false;
		AnnotationCollection _annotations = new AnnotationCollection ();
		bool _annotationsSpecified = false;
		
		public long MembershipId
		{
			get { return _membershipId; }
			set { _membershipId = value; }
		}
		
		[XmlIgnore]
		public bool MembershipIdSpecified
		{
			get { return _membershipIdSpecified; }
			set { _membershipIdSpecified = value; }
		}
		
		[XmlElement ("Type")]
		public string _Type
		{
			get { return _type; }
			set { _type = value; }
		}
		
		[XmlIgnore]
		public MemberType Type
		{
			get
			{
				try
				{
					return (MemberType)Enum.Parse (typeof (MemberType), _type);
				}
				catch
				{
					Log.Warn ("Unknown value '{0}'", _type);
					return MemberType.Unknown;
				}
			}
			set { _type = value.ToString (); }
		}
		
		[XmlElement ("State")]
		public string _State
		{
			get { return _state; }
			set { _state = value; }
		}
		
		[XmlIgnore]
		public MemberState State
		{
			get
			{
				try
				{
					return (MemberState)Enum.Parse (typeof (MemberState), _state);
				}
				catch
				{
					Log.Warn ("Unknown value '{0}'", _state);
					return MemberState.Unknown;
				}
			}
			set { _state = value.ToString (); }
		}
		
		public bool Deleted
		{
			get { return _deleted; }
			set { _deleted = value; }
		}
		
		[XmlIgnore]
		public bool DeletedSpecified
		{
			get { return _deletedSpecified; }
			set { _deletedSpecified = value; }
		}
		
		public DateTime LastChanged
		{
			get { return _lastChanged; }
			set { _lastChanged = value; }
		}
		
		[XmlIgnore]
		public bool LastChangedSpecified
		{
			get { return _lastChangedSpecified; }
			set { _lastChangedSpecified = value; }
		}
		
		[XmlArray]
		[XmlArrayItem (Type=typeof (Annotation))]
		public AnnotationCollection Annotations
		{
			get { return _annotations; }
			set { _annotations = value; }
		}
		
		[XmlIgnore]
		public bool AnnotationsSpecified
		{
			get { return _annotationsSpecified; }
			set { _annotationsSpecified = value; }
		}
	}
	
	public class MemberCollection : List<Member>
	{
	}
	
	// Used by regular msn contacts
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class PassportMember : Member
	{
		string _passportName;
		bool _isPassportNameHidden;
		bool _isPassportNameHiddenSpecified = false;
		long _passportId;
		bool _passportIdSpecified = false;
		long _cid;
		bool _cidSpecified = false;
		
		public string PassportName
		{
			get { return _passportName; }
			set { _passportName = value; }
		}
		
		public bool IsPassportNameHidden
		{
			get { return _isPassportNameHidden; }
			set { _isPassportNameHidden = value; }
		}
		
		[XmlIgnore]
		public bool IsPassportNameHiddenSpecified
		{
			get { return _isPassportNameHiddenSpecified; }
			set { _isPassportNameHiddenSpecified = value; }
		}
		
		public long PassportId
		{
			get { return _passportId; }
			set { _passportId = value; }
		}
		
		[XmlIgnore]
		public bool PassportIdSpecified
		{
			get { return _passportIdSpecified; }
			set { _passportIdSpecified = value; }
		}
		
		public long CID
		{
			get { return _cid; }
			set { _cid = value; }
		}
		
		[XmlIgnore]
		public bool CIDSpecified
		{
			get { return _cidSpecified; }
			set { _cidSpecified = value; }
		}
	}
	
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class EveryoneMember : Member
	{
	}
	
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class RoleMember : Member
	{
	}
	
	// EmailMember is used by non-msn contacts (eg. Yahoo)
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class EmailMember : Member
	{
		string _email;
		
		public string Email
		{
			get { return _email; }
			set { _email = value; }
		}
	}
	
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class PhoneMember : Member
	{
		string _phoneNumber;
		
		public string Phone
		{
			get { return _phoneNumber; }
			set { _phoneNumber = value; }
		}
	}
	
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class GroupMember : Member
	{
	}
	
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class ServiceMember : Member
	{
	}
	
	[XmlRoot ("Member", Namespace=SoapConstants.nsAddressBook)]
	public class DomainMember : Member
	{
	}
}
